#include "stdint.h"
#include "stdio.h"
#include "string.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"

#include "DevicesTime.h"
#include "DevicesQueue.h"
#include "DevicesUart.h"
#include "DevicesLed.h"

#include "taskNetwork.h"

#include "esp32c3_it.h"


void IRAM_ATTR uart_isr(void *arg)
{
    uart_dev_t *uart = (uart_dev_t *)arg;
    QueueType *ptypeQueue = (uart == &UART0) ? &g_TypeQueueUart0Read : &g_TypeQueueUart1Read;

    uart_ll_clr_intsts_mask(uart, UART_RXFIFO_FULL_INT_CLR | UART_RXFIFO_TOUT_INT_CLR);

    while(uart_ll_get_rxfifo_len(uart) > 0)
    {
        if(enumQueuePushByte(ptypeQueue, uart->ahb_fifo.val) != queueNormal)
            enumQueueClear(ptypeQueue);
    }

    vTaskNotifyGiveFromISR(g_TaskNetworkHand, NULL);
}
